package practiceProjects;

import java.time.LocalDate;
import java.time.Period;
import java.util.Scanner;

/**
 * @Project ：learn_java
 * @File ：HowOldAmIAtSometime.java
 * @IDE ：IntelliJ IDEA
 * @Author ：自由如风间
 * @Date ：2025/3/5 17:18
 * @Description ：计算在某一个具体日期我的年龄
 */

public class HowOldAmIAtSometime {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        // 用户指定日期
        LocalDate startDate = LocalDate.of(2004, 6, 26);
        // LocalDate endDate = LocalDate.of(2022, 3, 15);

        System.out.print("请输入结束日期（格式：yyyy-MM-dd）: ");
        String endDateStr = scanner.nextLine();
        LocalDate endDate = LocalDate.parse(endDateStr);

        // 计算相差的年数、月数和天数
        Period period = Period.between(startDate, endDate);
        int years = period.getYears();
        int months = period.getMonths();
        int days = period.getDays();

        System.out.println("当时年龄为: " + years + " 岁, " + months + " 月, " + days + " 天");
    }
}
